package com.audi.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.drawable.BitmapDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;

import com.audi.R;
import com.audi.dto.MemberItem;

public class RootAccessHomeMemberAdapter extends BaseAdapter {
	private Activity mActivity;
	private ArrayList<MemberItem> mMemberList;
	public RootAccessHomeMemberAdapter(Activity activity,
			ArrayList<MemberItem> memberList) {
		mActivity = activity;
		mMemberList = memberList;
	}
	public void setDataForAdapter(ArrayList<MemberItem> listMember)
	{
		this.mMemberList =listMember;
		this.notifyDataSetChanged();
	}
	public int getCount() {
		return mMemberList.size();
	}

	public MemberItem getItem(int pos) {
		return mMemberList.get(pos);
	}

	public long getItemId(int pos) {
		return pos;
	}

	@SuppressLint("InflateParams")
	public View getView(int i, View convertView, ViewGroup viewgroup) {
		final MemberItem item = mMemberList.get(i);
		ViewHolder viewholderHomeMember = null;
		if (convertView == null) {
			viewholderHomeMember = new ViewHolder();
			convertView = LayoutInflater.from(mActivity).inflate(
					R.layout.row_root_access_home_member, null);
			viewholderHomeMember.imvMemberIcon = (ImageView) convertView
					.findViewById(R.id.imv_member_icon);
			viewholderHomeMember.txtMemberName = (TextView) convertView
					.findViewById(R.id.txt_member_name);
			viewholderHomeMember.txtMemberEmail = (TextView) convertView
					.findViewById(R.id.txt_member_email);

			convertView.setTag(viewholderHomeMember);
		} else {
			viewholderHomeMember = (ViewHolder) convertView.getTag();
		}

		// set Data for View
		if (TextUtils.isEmpty(item.getMemberPhoto())) {
			viewholderHomeMember.imvMemberIcon.setImageResource(R.drawable.member);
		} else {
			BitmapDrawable bitmapDrawable = new BitmapDrawable(
					mActivity.getResources(), item.getMemberPhoto());
			viewholderHomeMember.imvMemberIcon.setImageDrawable(bitmapDrawable);
		}

		viewholderHomeMember.txtMemberName.setText(item.getMemberName());
		viewholderHomeMember.txtMemberEmail.setText(item.getMemberEmail());

		return convertView;
	}

	static class ViewHolder {
		public ImageView imvMemberIcon;
		public TextView txtMemberName;
		public TextView txtMemberEmail;
	}

	public void swapItems(ArrayList<MemberItem> mMemberRootAccessList) {
		// TODO Auto-generated method stub
		
	}
}
